﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EZCRS.HCMS.SqlClient;
using System.Data.SqlClient;
using System.Data;

namespace EZCRS.HCMS.Bll.userinfo
{
    public class Bllcardinfo:MainBase
    {
        #region 常客联系方式信息列表
        public DataTable Address_List(string Uid)
        {
            return new sql_AdminAddress().Address_List(CFun.VerifySQL(Uid));
        }
        #endregion
        #region 常客联系方式信息添加、修改
        /// <summary>
        /// 修改或添加常客联系方式信息
        /// </summary>
        /// <returns></returns>
        public bool Address_Add(string Uid, string Adrtopics, string Usrcountry, string Usrprovince, string Usrcity, string Adrcomment, string Adrpost, string Adrtel, string Adrfax, string Adrcontact, string Indate, string Usetime, string Adrid)
        {
            return new sql_AdminAddress().Address_Add(Uid, Adrtopics, Usrcountry, Usrprovince, Usrcity, Adrcomment, Adrpost, Adrtel, Adrfax, Adrcontact, Indate, Usetime, Adrid);
        }
        #endregion
        #region 常客联系方式Info数据的显示,显示一条数据
        public DataRow Address_Item(string Adrid)
        {
            return new sql_AdminAddress().Address_Item(CFun.VerifySQL(Adrid));
        }
        #endregion
        #region 常客联系方式的删除
        public bool Address_Del(string Adrid)
        {
            return new sql_AdminAddress().Address_Del(CFun.VerifySQL(Adrid));
        }
        #endregion

        #region 分配卡号
        /// <summary>
        /// 分配卡号
        /// </summary>
        /// <returns></returns>
        public bool CardNumb_Distribute(string Gid, string Uid, string Cardid, string Useadm, string Comment, out SqlCommand Outcmd)
        {
            return new sql_AdmCardNumb().CardNumb_Distribute(Gid, Uid, Cardid, Useadm, Comment, out Outcmd);
        }
        #endregion
        #region 常客会员卡的批量删除
        public bool CardNumb_Del(string Cardid)
        {
            return new sql_AdmCardNumb().CardNumb_Del(Cardid);
        }
        #endregion
        #region 常客会员卡列表
        public DataTable CardNumb_List(string StrWhere)
        {
            return new sql_AdmCardNumb().CardNumb_List(StrWhere);
        }

        public DataSet CardNumb_List1(int cpage, string StrWhere)
        {
            return new sql_AdmCardNumb().CardNumb_List1(cpage, StrWhere);
        }

        public DataTable CardNumb_List(string StrWhere, string SType)
        {
            return new sql_AdmCardNumb().CardNumb_List(StrWhere, SType);
        }
        #endregion
        #region 常客会员卡信息批量添加
        /// <summary>
        /// 批量添加常客会员卡信息
        /// </summary>
        /// <returns></returns>
        public bool CardNumb_Add(string Orgid, string Orgtype, string Cardtype, string Templateno, string Startnum, string Endnum, string Median, out SqlCommand Outcmd)
        {
            return new sql_AdmCardNumb().CardNumb_Add(Orgid, Orgtype, Cardtype, Templateno, Startnum, Endnum, Median, out Outcmd);
        }
        #endregion
        #region 常客会员卡信息添加
        /// <summary>
        /// 添加常客会员卡信息
        /// </summary>
        /// <returns></returns>
        public bool CardNumb_Add(string Orgid, string Orgtype, string Cardnumber, string Cardpassword, string Cardtype)
        {
            return new sql_AdmCardNumb().CardNumb_Add(Orgid, Orgtype, Cardnumber, Cardpassword, Cardtype);
        }
        #endregion

        #region 批量导入
        /// <summary>
        /// 批量导入，返回 成功、失败数
        /// </summary>
        /// <param name="Orgid">组织编号</param>
        /// <param name="Orgtype">组织类型</param>
        /// <param name="cardtxt">卡号列</param>
        /// <param name="Cardtype">卡类型</param>
        /// <returns></returns>
        public int[] CardNumb_Add(string Orgid, string Orgtype, string cardtxt, string Cardtype)
        {
            return new sql_AdmCardNumb().CardNumb_Add(Orgid, Orgtype, cardtxt, Cardtype);
        }
        #endregion


        #region ====================================
      

        /// <summary>
        /// 更新常客可用积分或冻结积分总数
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="types">1=可用积分；2=冻结积分；其他1、2都更新</param>
        public static void statscore(int uid, int types)
        {
            sql_AdmCardUser.statscore(uid, types);
        }

        #region 常客列表
        public DataTable CardUser_List(string StrWhere)
        {
            return new sql_AdmCardUser().CardUser_List(StrWhere);
        }
        #endregion


        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet CardUser_List(int PageSize, int PageIndex, string StrWhere, string ViewName)
        {
            return new sql_AdmCardUser().CardUser_List(PageSize, PageIndex, StrWhere, ViewName);
        }
        #region 常客Info数据的显示,显示一条数据
        public DataRow CardUser_Item(string UId, int GId)
        {
            UId = CFun.VerifySQL(UId);

            return new sql_AdmCardUser().CardUser_Item(UId, GId);
        }
        #endregion
        #region 常客Info数据的,以及常客和其他有关联的几张表的数据的同时显示,显示一条数据
        public DataSet CardUser_Item2(string UId, int GId)
        {
            UId = CFun.VerifySQL(UId);
            return new sql_AdmCardUser().CardUser_Item2(UId, GId);
        }
        #endregion
        #region 常客信息添加、修改
        /// <summary>
        /// 修改或添加常客信息
        /// </summary>
        /// <returns></returns>
        public bool CardUser_Add(string Lvlid, string Endyear, string Scores, string Emailformat, string Emaillanguage, string Usrfirstname, string Usrlastname, string Usrgender, string Usrbirthday, string Usrnationality, string Idtype, string Idno, string Usrcountry, string Usrprovince, string Usrcity, string Smoke, string Bed, string Pillow, string Usrstatus, string Ademail, string Admobile, string Uid)
        {
            Uid = CFun.VerifySQL(Uid);

            return new sql_AdmCardUser().CardUser_Add(Lvlid, Endyear, Scores, Emailformat, Emaillanguage, Usrfirstname, Usrlastname, Usrgender, Usrbirthday, Usrnationality, Idtype, Idno, Usrcountry, Usrprovince, Usrcity, Smoke, Bed, Pillow, Usrstatus, Ademail, Admobile, Uid);
        }
        #endregion
        #region 常客信息添加、修改
        /// <summary>
        /// 修改或添加常客信息
        /// </summary>
        /// <returns></returns>
        public bool CardUser_Add(string Orgid, string Orgtype, string Unumber, string Lvlid, string Endyear, string Scores, string Usrname, string Usrpassword, string Usremail, string Emailformat, string Emaillanguage, string Usrmobile, string Usrfirstname, string Usrlastname, string Usrgender, string Usrbirthday, string Usrnationality, string Idtype, string Idno, string Usrcountry, string Usrprovince, string Usrcity, string Smoke, string Bed, string Pillow, string Regdate, string Logdate, string Logip, string Logcount, string Usrstatus, string Uid)
        {
            return new sql_AdmCardUser().CardUser_Add(Orgid, Orgtype, Unumber, Lvlid, Endyear, Scores, Usrname, Usrpassword, Usremail, Emailformat, Emaillanguage, Usrmobile, Usrfirstname, Usrlastname, Usrgender, Usrbirthday, Usrnationality, Idtype, Idno, Usrcountry, Usrprovince, Usrcity, Smoke, Bed, Pillow, Regdate, Logdate, Logip, Logcount, Usrstatus, Uid);
        }
        #endregion
        #region 常客信息的删除
        public bool CardUser_Del(string Uid)
        {
            return new sql_AdmCardUser().CardUser_Del(CFun.VerifySQL(Uid));
        }
        #endregion
        #region 常客用户表的用户名的添加或者修改
        /// <summary>
        /// 添加或者修改常客用户表的用户名
        /// </summary>
        /// <returns></returns>
        public bool CardUserUserName_Add(string UserName, string Gid, string Uid, string Userid)
        {
            Userid = CFun.VerifySQL(Userid);
            return new sql_AdmCardUser().CardUserUserName_Add(UserName, Gid, Uid, Userid);
        }
        #endregion
        #region 常客用户表的邮件的添加或者修改
        /// <summary>
        /// 添加或者修改常客用户表的邮件
        /// </summary>
        /// <returns></returns>
        public bool CardUserEmail_Add(string Email, string Gid, string Uid, string Eid)
        {
            Eid = CFun.VerifySQL(Eid);
            Uid = CFun.VerifySQL(Uid);
            return new sql_AdmCardUser().CardUserEmail_Add(Email, Gid, Uid, Eid);
        }
        #endregion

        #region 常客用户表的手机号码的添加或者修改
        /// <summary>
        /// 添加或者修改常客用户表的手机号码
        /// </summary>
        /// <returns></returns>
        public bool CardUserMobile_Add(string Mobnumb, string Gid, string Uid, string Mobid)
        {
            Mobid = CFun.VerifySQL(Mobid);
            Uid = CFun.VerifySQL(Uid);
            return new sql_AdmCardUser().CardUserMobile_Add(Mobnumb, Gid, Uid, Mobid);
        }
        #endregion
        #region 常客用户表的密码初始化
        /// <summary>
        /// 添加或者修改常客用户表的手机号码
        /// </summary>
        /// <returns></returns>
        public bool User_InitPass(string Usrpassword, string Uid, out string Pass)
        {
            Uid = CFun.VerifySQL(Uid);

            Pass = "";
            if (Usrpassword == "")
                Pass = CreatePassword();
            else
            {
                if (Common.CheckUserPass(Usrpassword))
                    Pass = Usrpassword;
                else
                    return false;
            }
            Pass = CFun.MD5(Pass);

            return new sql_AdmCardUser().User_InitPass(Pass, Uid);           
        }
        #endregion
        private string CreatePassword()
        {
            Random r = new Random();
            int rl = r.Next(10000, 99999);
            return rl.ToString();
        }
        public DataTable CardUser_Status()
        {
            string[] LogData = Common.DoubleStatus;

            DataTable dt = new DataTable();
            DataColumn dc1 = dt.Columns.Add("sid", Type.GetType("System.String"));
            DataColumn dc2 = dt.Columns.Add("sname", Type.GetType("System.String"));


            for (int i = 0; i < LogData.Length; i++)
            {
                DataRow dr = dt.NewRow();
                dr["sid"] = LogData[i].Split(',')[0];
                dr["sname"] = LogData[i].Split(',')[LanguageNumber+1];

                dt.Rows.Add(dr);
            }
            return dt;
        }


        /// <summary>
        /// 待升级用户列表
        /// </summary>
        /// <param name="stime">查询开始时间</param>
        /// <param name="etime">查询结束时间</param>
        /// <param name="orders">排序</param>
        /// <param name="cpage">页数</param>
        /// <returns></returns>
        public DataSet upgradelist(string gid, string stime, string etime, string orders, int cpage)
        {
            return new sql_AdmCardUser().upgradelist(gid, stime, etime, orders, cpage);
        }

        /// <summary>
        /// 删除待升级用户
        /// </summary>
        /// <param name="gid"></param>
        /// <param name="logid">带升级用户编号组,逗号隔开</param>
        /// <returns>成功数量</returns>
        public int upgradedel(string gid, string logid)
        {
            return new sql_AdmCardUser().upgradedel(gid, logid);
        }

        /// <summary>
        /// 处理升级
        /// </summary>
        /// <param name="gid"></param>
        /// <param name="logid">待升级用户编号</param>
        /// <returns>升级是否成功</returns>
        public bool userupgrade(string gid, string logid)
        {
            DataRow dr=new sql_AdmCardUser().userupgrade(gid,logid);
            if (dr!=null)
            {
                //保存日志
                Common.SaveLog(71, dr["usrfirstname"].ToString() + "." + dr["usrlastname"].ToString() + "用户升级成功.");
                return true;
            }
            else
                return false;
        }
        #endregion
    }
}
